//
//  CTPersonalNameModifyView.m
//  ConstellationTalk_0.1
//
//  Created by riley on 15/6/29.
//  Copyright (c) 2015年 riley chu. All rights reserved.
//

#import "CTPersonalNameModifyView.h"
#import "CTDebugManager.h"
#import "CTAppLanguage.h"
#import "CTHeader.h"
#import "UIViewAdditions.h"
#import "CTAppLanguage.h"


@interface CTPersonalNameModifyView()
{
    UIView          *topView;
    UITextField     *newNameTextField;
    UILabel         *nameContentLabel;
}

@end

@implementation CTPersonalNameModifyView

- (void)dealloc
{
    [topView removeFromSuperview];
    topView = nil;
    [newNameTextField removeFromSuperview];
    newNameTextField = nil;
    [nameContentLabel removeFromSuperview];
    nameContentLabel = nil;
    
    [CTDebugManager showDebugLogInfo:@"dealloc : CTSetView Is Removed!!!"];
}
- (instancetype)init
{
    self = [super init];
    if (self)
    {
//        userItem = [CTUser userInfo];
        
        self.frame = CGRectMake(0, 0,CT_HEADER_SCREEN_WIDTH,CT_HEADER_SCREEN_HEIGHT);
        self.backgroundColor = CT_HEADER_WHITE_COLOR;
        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapGestureAction:)];
        [self addGestureRecognizer:tapGesture];
        [self createSetTitleView];
        [self personalNameModifyView];
    }
    return self;
}
//创建标题
- (void)createSetTitleView
{
    topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CT_HEADER_SCREEN_WIDTH, 64)];
    topView.backgroundColor = CT_HEADER_WHITE_COLOR;
    topView.alpha =0.98;
    [self addSubview:topView];
    
    //标题
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, CT_HEADER_SCREEN_WIDTH, 44)];
    titleLabel.text = [CTAppLanguage localizedStringForKey:@"userNickNameView_title_text" withValue:nil withTable:@"Language"];
    titleLabel.font = [UIFont systemFontOfSize:19.0f];
    titleLabel.textColor = CT_HEADER_GREEN_COLOR;
    
    titleLabel.textAlignment = NSTextAlignmentCenter;
    [topView addSubview:titleLabel];
    
    //返回按钮
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    backButton.frame = CGRectMake(0, 20, 44, 44);
    [backButton addTarget:self action:@selector(backButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [backButton setImage:[UIImage imageNamed:CT_HEADER_BACK_IMAGE] forState:UIControlStateNormal];
    [backButton setImage:[UIImage imageNamed:CT_HEADER_BACK_IMAGE_CLICK] forState:UIControlStateHighlighted];
    [topView addSubview:backButton];
    
    UIButton *finishButton = [UIButton buttonWithType:UIButtonTypeCustom];
    finishButton.frame = CGRectMake(CT_HEADER_SCREEN_WIDTH-44,20 , 44, 44);
    [finishButton addTarget:self action:@selector(finishButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [finishButton setTitle:[CTAppLanguage localizedStringForKey:@"userNickNameView_saveLabel_text" withValue:nil withTable:@"Language"] forState:UIControlStateNormal];
    finishButton.titleLabel.font = [UIFont systemFontOfSize:15.0f];
    [finishButton setTitleColor:CT_HEADER_GREEN_COLOR forState:UIControlStateNormal];
    [finishButton setTitleColor:CT_HEADER_GREEN_COLOR forState:UIControlStateHighlighted];
    [topView addSubview:finishButton];

    
    UILabel * topBottomLine = [[UILabel alloc]initWithFrame:CGRectMake(0, topView.height-0.5, CT_HEADER_SCREEN_WIDTH, 0.5)];
    topBottomLine.backgroundColor = CT_HEADER_DEEPLINE_COLOR;
    [topView addSubview:topBottomLine];
}
- (void)personalNameModifyView
{
    UILabel * viewTopLine = [[UILabel alloc]initWithFrame:CGRectMake(0, topView.bottom+20, CT_HEADER_SCREEN_WIDTH, 0.5)];
    viewTopLine.backgroundColor = CT_HEADER_BRIGHTLINE_COLOR;
    [self addSubview:viewTopLine];
    
    UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, viewTopLine.bottom, 100, 48)];
    nameLabel.font = [UIFont systemFontOfSize:18];
    nameLabel.text = [CTAppLanguage localizedStringForKey:@"userNickNameView_nickLabel_text" withValue:nil withTable:@"Language"];
    nameLabel.textColor = CT_HEADER_BLACK_COLOR;
    nameLabel.textAlignment  = NSTextAlignmentLeft;
    [self addSubview:nameLabel];
    
    nameContentLabel  = [[UILabel alloc]initWithFrame:CGRectMake(CT_HEADER_SCREEN_WIDTH-200-10, viewTopLine.bottom, 200, 48)];
    nameContentLabel.font = [UIFont systemFontOfSize:15];
    nameContentLabel.textColor = CT_HEADER_DEEPLINE_COLOR;
    nameContentLabel.textAlignment  = NSTextAlignmentRight;
    [self addSubview:nameContentLabel];
    
    
    
    UILabel * viewMiddleLine = [[UILabel alloc]initWithFrame:CGRectMake(10, nameLabel.bottom, CT_HEADER_SCREEN_WIDTH-20, 0.5)];
    viewMiddleLine.backgroundColor = CT_HEADER_BRIGHTLINE_COLOR;
    [self addSubview:viewMiddleLine];
    
//    UILabel *newNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, viewMiddleLine.bottom, 100, 48)];
//    newNameLabel.font = [UIFont systemFontOfSize:18];
//    newNameLabel.text = [CTAppLanguage localizedStringForKey:@"userNickNameView_newNIckLabel_text" withValue:nil withTable:@"Language"];
//    newNameLabel.textColor = CT_HEADER_BLACK_COLOR;
//    newNameLabel.textAlignment  = NSTextAlignmentLeft;
//    [self addSubview:newNameLabel];
    
    newNameTextField  = [[UITextField alloc]initWithFrame:CGRectMake(10, viewMiddleLine.bottom, CT_HEADER_SCREEN_WIDTH, 48)];
    newNameTextField.placeholder = [CTAppLanguage localizedStringForKey:@"userNickNameView_newNIckLabel_text" withValue:nil withTable:@"Language"];
    newNameTextField.font = [UIFont systemFontOfSize:15];
    newNameTextField.textColor = CT_HEADER_DEEPLINE_COLOR;
    newNameTextField.textAlignment  = NSTextAlignmentLeft;
    [self addSubview:newNameTextField];
    
    
    UILabel * viewBottomeLine = [[UILabel alloc]initWithFrame:CGRectMake(0, newNameTextField.bottom, CT_HEADER_SCREEN_WIDTH, 0.5)];
    viewBottomeLine.backgroundColor = CT_HEADER_BRIGHTLINE_COLOR;
    [self addSubview:viewBottomeLine];
    
//    UILabel *hintLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, viewBottomeLine.bottom+25, CT_HEADER_SCREEN_WIDTH-20, 15)];
//    hintLabel.text = [CTAppLanguage localizedStringForKey:@"userNickNameView_promptLabel_text" withValue:nil withTable:@"Language"];
//    hintLabel.font = [UIFont systemFontOfSize:15];
//    hintLabel.textColor = CT_HEADER_DEEPLINE_COLOR;
//    hintLabel.textAlignment  = NSTextAlignmentLeft;
//    [self addSubview:hintLabel];
    
}
//收回键盘
- (void)tapGestureAction:(UITapGestureRecognizer *)sender
{
    [newNameTextField resignFirstResponder];
}

#pragma mark  TitleView_Action
- (void)backButtonAction:(UIButton *)sender
{
    if ([self.delegate respondsToSelector:@selector(personalNameModifyViewSelectedBackBtnAction:)])
    {
        [self.delegate personalNameModifyViewSelectedBackBtnAction:self];
    }
}
- (void)finishButtonAction:(UIButton *)sender
{
    [newNameTextField resignFirstResponder];
    
    if ([self.delegate respondsToSelector:@selector(personalNameModifyViewSelectedSaveBtnAction:withSexString:)])
    {
        [self.delegate personalNameModifyViewSelectedSaveBtnAction:self withSexString:newNameTextField.text];
    }
}
#pragma  mark - setter -
- (void)setNameLabelText:(NSString *)nameLabelStr
{
    nameContentLabel.text = nameLabelStr;
}
@end
